package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.domain.TypeFeedback;
import com.ruoyi.system.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.UserFeedbackMapper;
import com.ruoyi.system.domain.UserFeedback;
import com.ruoyi.system.service.IUserFeedbackService;

/**
 * 问题反馈Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Service
public class UserFeedbackServiceImpl implements IUserFeedbackService {
    @Autowired
    private UserFeedbackMapper userFeedbackMapper;

    /**
     * 查询问题反馈
     *
     * @param id 问题反馈主键
     * @return 问题反馈
     */
    @Override
    public UserFeedback selectUserFeedbackById(Long id) {
        return userFeedbackMapper.selectUserFeedbackById(id);
    }

    /**
     * 查询问题反馈列表
     *
     * @param userFeedback 问题反馈
     * @return 问题反馈
     */
    @Override
    public List<UserFeedback> selectUserFeedbackList(UserFeedback userFeedback) {
        List<UserFeedback> list = userFeedbackMapper.selectUserFeedbackList(userFeedback);
        for (UserFeedback feedback : list) {
            // 用户名称
            String userName = userFeedbackMapper.selectUserNameById(feedback.getUserId());
            feedback.setUserName(userName);
            // 类型名称
            String typeNameStr = userFeedbackMapper.selectTypeNameById(feedback.getTypeId());
            feedback.setTypeName(typeNameStr);
            System.err.println(feedback.getTypeName());
        }
        return list;
    }

    /**
     * 新增问题反馈
     *
     * @param userFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int insertUserFeedback(UserFeedback userFeedback) {
        userFeedback.setCreateTime(DateUtils.getNowDate());
        return userFeedbackMapper.insertUserFeedback(userFeedback);
    }

    /**
     * 修改问题反馈
     *
     * @param userFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int updateUserFeedback(UserFeedback userFeedback) {
        userFeedback.setUpdateTime(DateUtils.getNowDate());
        return userFeedbackMapper.updateUserFeedback(userFeedback);
    }

    /**
     * 批量删除问题反馈
     *
     * @param ids 需要删除的问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteUserFeedbackByIds(Long[] ids) {
        return userFeedbackMapper.deleteUserFeedbackByIds(ids);
    }

    /**
     * 删除问题反馈信息
     *
     * @param id 问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteUserFeedbackById(Long id) {
        return userFeedbackMapper.deleteUserFeedbackById(id);
    }

    /**
     * 查询问题反馈列表
     *
     * @return
     */
    @Override
    public List<TypeFeedback> selectTypeList() {
        List<TypeFeedback> list = userFeedbackMapper.selectTypeList();
        System.err.println("sdasdsadasd" + list);
        return list;
    }

    @Override
    public List<User> selectUserList() {
        return userFeedbackMapper.selectUserList();
    }
}
